package com.william.lifetraxer;

import android.content.DialogInterface;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;

import com.william.lifetraxer.utils.DbHandler;
import com.william.lifetraxer.utils.UserDb;

public class DeleteUser extends BasicActivity {

	private DbHandler mUserDbHandler = new DbHandler(this);
	private ListView users = null;
	private Button delete ;
	private Button cancel ;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.delete_user);
		this.setTitle(this.getResources().getString(
				R.string.delete_user_title_text));
		initViews();
	}
	
	private void initViews(){
		delete = (Button) findViewById(R.id.delete_user_delete);
		delete.setOnClickListener(
				new Button.OnClickListener(){

					@Override
					public void onClick(View v) {
						showOnDeleteUserDialog();
					}
					
				}
				);
		
		cancel = (Button) findViewById(R.id.delete_user_cancel);
		cancel.setOnClickListener(
				new Button.OnClickListener(){

					@Override
					public void onClick(View v) {
						DeleteUser.this.finish();
					}
					 
				}
				);
		users = (ListView) findViewById(R.id.delete_user_listview_users);
		getUsers();
	}
	
	private void showOnDeleteUserDialog(){
		int icon = R.drawable.dialog_icon;
		String titleMsg = this.getResources().getString(R.string.delete_user_dialog_on_delete_title_text);
		String posButtonMsg = this.getResources().getString(R.string.delete_user_dialog_on_delete_pos_msg_text);
		String nagButtonMsg = this.getResources().getString(R.string.delete_user_dialog_on_delete_nag_msg_text);
		String mainMsg = this.getResources().getString(R.string.delete_user_dialog_on_delete_content_text);
		
		DialogInterface.OnClickListener posListener = new DialogInterface.OnClickListener(){

			@Override
			public void onClick(DialogInterface dialog, int which) {
			}
			
		};
		
		DialogInterface.OnClickListener nagListener = new DialogInterface.OnClickListener(){

			@Override
			public void onClick(DialogInterface dialog, int which) {
				
			}
			
		};
		
		this.createSimpleDialog(icon, titleMsg, mainMsg, posButtonMsg, posListener, nagButtonMsg, nagListener).show();
	}
	
	private void getUsers() {
		Cursor userCursor = this.mUserDbHandler.getUsers();
		SimpleCursorAdapter sca = new SimpleCursorAdapter(this,
				R.layout.delete_user_item_style, userCursor,
				new String[] { UserDb.UserColumns.USERNAME },
				new int[] { R.id.content_list_item_textview_username });
		users.setAdapter(sca);
	}

}
